<div class="row-fluid {$name}" >
    <table class="table table-striped table-hover table-bordered table-task">
        <thead>
	        <tr>
	            <th class="span5" colspan="5">{$tca.label}</th>
	        </tr>
        </thead>
        <tbody>
        <notempty name="tca[data]">
        	<volist name="tca[data]" id="voo">
        	<tr>
            	<td>
					<select class="select span12" name="{$name}[type][]">
						<!-- <option value="">请选择价格对象类型</option> -->
						<volist name="type" id="vo">
							<option <eq name="voo.type" value="$vo[0]">selected="selected"</eq> value="{$vo[0]}">{$vo[1]}</option>
						</volist>
					</select>
				</td>
				<td>
					<select class="span12" name="{$name}[priceobj][]" data-value="<if condition='$voo.type eq 1'>{$voo.user_id}<elseif condition='$voo.type eq 2' />{$voo.pricegroup}<else />0</if>">
						<!-- <option value="">请选择具体价格对象</option> -->
					</select>
				</td>
				<td>
					<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price][]" value="{$voo.price}" placeholder="商品价格"/>
				</td>
				<td>
					<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price_unit][]" value="<eq name='voo.price_unit' value='1'>{$info.nunit}<else />{$info.munit}</eq>" placeholder="定价单位"/>
				</td>
				<td>
					<a style="margin-top: 3px; margin-left: 5px;" class="btn add-price" href="javascript:;"><i class="icon-plus"></i></a>
                    <a style="margin-top: 3px; margin-left: 5px;" class="btn red remove-price" href="javascript:;" data-id="{$voo.id}"><i class="icon-minus"></i></a>
				</td>
            </tr>
            </volist>
         <else />
            <tr>
            	<td>
					<select class="select span12" name="{$name}[type][]">
						<option value="">请选择价格对象类型</option>
						<volist name="type" id="voo">
							<option value="{$voo[0]}">{$voo[1]}</option>
						</volist>
					</select>
				</td>
				<td>
					<select class="span12" name="{$name}[priceobj][]">
						<option value="">请选择具体价格对象</option>
					</select>
				</td>
				<td>
					<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price][]" placeholder="商品价格"/>
				</td>
				<td>
					<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price_unit][]" placeholder="定价单位"/>
				</td>
				<td>
					<a style="margin-top: 3px; margin-left: 5px;" class="btn add-price" href="javascript:;"><i class="icon-plus"></i></a>
                    <a style="margin-top: 3px; margin-left: 5px;" class="btn red remove-price" href="javascript:;"><i class="icon-minus"></i></a>
				</td>
            </tr>
        </notempty>
        </tbody>
    </table>
</div>
<script src="__TMPL__Public/plugins/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
    	//商品价格
		$(".add-price").live("click", function(){
		    var cont_answer = '<tr>'
            					+'<td>'
            					+'<select class="select span12" name="{$name}[type][]">'
            					+'<option value="">请选择价格对象类型</option>'
            					+'<volist name="type" id="voo">'
            					+'<option value="{$voo[0]}">{$voo[1]}</option>'
            					+'</volist>'
            					+'</select>'
            					+'</td>'
            					+'<td>'
            					+'<select class="span12" name="{$name}[priceobj][]">'
            					+'<option value="">请选择具体价格对象</option>'
            					+'</select>'
            					+'</td>'
            					+'<td>'
            					+'<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price][]" placeholder="商品价格"/>'
            					+'</td>'
            					+'<td>'
            					+'<input style="margin-bottom: 3px;" type="text" class="baozhi" name="{$name}[price_unit][]" placeholder="定价单位"/>'
            					+'</td>'
            					+'<td>'
            					+'<a style="margin-top: 3px; margin-left: 5px;" class="btn add-price" href="javascript:;"><i class="icon-plus"></i></a>'
            					+'<a style="margin-top: 3px; margin-left: 5px;" class="btn red remove-price" href="javascript:;"><i class="icon-minus"></i></a>'
            					+'</td>'
            					+'</tr>';
		    $(this).parents("tbody").append(cont_answer);
		    
		});
		$(".remove-price").live("click", function(){
		    var _this = $(this);
		    var id = $(this).data("id");
		    var url = "{:U(CONTROLLER_NAME.'/delprice')}";
		    if(id){
		        
		        custom_confirm('您确定要删除吗？', function (){
		        	$.post(url,{id:id},function(data){
			            if(data.status == 1){
			                _this.parents("tr").remove();
			            }else{
			                alert(data.info);
			            }
			        },'json');
	            });
		        
		    }else{
		        if(_this.parents("tbody").find(".remove-price").length > 1){
		            $(this).parents("tr").remove();
		        }
		    }
		});
		//选择类型
		$('[name="{$name}[type][]"]').die().live('change', function(){
            var _this = $(this);
            var type = _this.val();
            var send_url = "{:U(CONTROLLER_NAME.'/getObjList')}";
            $.ajax({
                type:'post',
                url:send_url,
                data:{'type':type},
                dataType:'json',
                success:function(json){
                	var _next = _this.closest('tr').find('[name="{$name}[priceobj][]"]');
					var value_selected = _next.attr('data-value');
                    //var list = '<option value="">请选择具体价格对象</option>';
                    var list = '';
                    for(i=0;i<json.data.length;i++){
                        list += '<option value="'+json.data[i][0]+'">'+json.data[i][1]+'</option>';
                    }
                    _next.html(list);
                    //if(value_selected){
						_next.find('option[value='+value_selected+']').prop('selected',true).attr('selected','selected');
					//}
                }
            })
        })
		//加载完模拟触发选择类型
        $('[name="{$name}[type][]"]').trigger('change');
    });
</script>